package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanKuJianKangZhengSavePO;
import com.ct.application.shipping.model.po.ChuanYuanKuJianKangZhengSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanKuJianKangZhengVO;
import com.ct.application.shipping.service.ChuanYuanKuJianKangZhengService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 船员证书-健康证配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员证书-健康证",path="/api/v1/chuanyuankujiankangzheng",code = "P1000",sorted = 15)
public class ChuanYuanKuJianKangZhengController extends BaseController {

    @Resource
    private ChuanYuanKuJianKangZhengService chuanYuanKuJianKangZhengService;

    /**
     * 查询船员证书-健康证列表
     * @param chuanYuanKuJianKangZhengSearchPO
     * @return
     */
    @PostMapping("/chuanyuankujiankangzheng/list")
    @PermissionApi(title = "查询船员证书-健康证列表",path="/api/v1/chuanyuankujiankangzheng/list",code = "P1001",sorted = 1)
    public Page<ChuanYuanKuJianKangZhengVO> findChuanYuanKuJianKangZhengs(@Validated @RequestBody ChuanYuanKuJianKangZhengSearchPO chuanYuanKuJianKangZhengSearchPO) {
        return chuanYuanKuJianKangZhengService.findChuanYuanKuJianKangZheng(chuanYuanKuJianKangZhengSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuankujiankangzheng/saveupdate")
    @ApiLog("船员证书-健康证保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书-健康证保存和更新",path="/api/v1/chuanyuankujiankangzheng/saveupdate",code = "P1003",sorted = 3)
    public ChuanYuanKuJianKangZhengVO saveUpdateChuanYuanKuJianKangZheng(@Validated @RequestBody ChuanYuanKuJianKangZhengSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanKuJianKangZhengService.updateChuanYuanKuJianKangZheng(savePO);
        }else {
            return chuanYuanKuJianKangZhengService.saveChuanYuanKuJianKangZheng(savePO);
        }
    }

    /**
     * 根据id查询船员证书-健康证
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankujiankangzheng/get/{id}")
    @PermissionApi(title = "根据id查询船员证书-健康证",path="/api/v1/chuanyuankujiankangzheng/get/{id}",code = "P1004",sorted = 4)
    public ChuanYuanKuJianKangZhengVO getChuanYuanKuJianKangZhengById(@PathVariable("id") Long id) {
        return chuanYuanKuJianKangZhengService.getChuanYuanKuJianKangZheng(id);
    }


    /**
     * 根据id删除船员证书-健康证
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankujiankangzheng/del/{id}")
    @ApiLog("根据id删除船员证书-健康证")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船员证书-健康证",path="/api/v1/chuanyuankujiankangzheng/del/{id}",code = "P1005",sorted = 5)
    public Boolean delChuanYuanKuJianKangZhengById(@PathVariable("id") Long id) {
        return chuanYuanKuJianKangZhengService.delChuanYuanKuJianKangZheng(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuankujiankangzheng/update/status")
    @ApiLog("船员证书-健康证修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书-健康证修改状态",path="/api/v1/chuanyuankujiankangzheng/update/status",code = "P1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanKuJianKangZhengService.updateStatus(statusRequest);
    }
}
